package com.petalsgroup.petals.web.servlet.InformServlet;

import com.petalsgroup.petals.pojo.ReasonDO;
import com.petalsgroup.petals.pojo.ResultInfo;
import com.petalsgroup.petals.service.Inform.InformService;
import com.petalsgroup.petals.service.Inform.impl.InformServiceImpl;
import com.petalsgroup.petals.web.BaseServlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/inform/*")
public class InformServlet extends BaseServlet {
    InformService is=new InformServiceImpl();

    /**
     * 查看该评论是否已经被该用户举报过已经被举报，返回提示信息已经举报过
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     * @auther wgd
     */
    public void findComInform(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String com_id=req.getParameter("com_id");
        String uid=req.getParameter("uid");
        Boolean flag=is.findComInform(com_id,uid);
        System.out.println(flag);
        ResultInfo info = new ResultInfo();
        if (flag)
        {
            info.setFlag(true);
            info.setErrorMsg("该评论已经被举报过！");
        }else {
            info.setFlag(false);
        }
        writeValue(resp,info);
    }

    /**
     * 获取所有的举报原因
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     * @auther wgd
     */
    public void getReason(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<ReasonDO> list=is.getReason();
        ResultInfo info = new ResultInfo();
        info.setData(list);
        writeValue(resp,info);
    }

    /**
     * 增加该评论的举报信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     * @auther wgd
     */
    public void comInform(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("进入");
        String com_id=req.getParameter("com_id");
        System.out.println(com_id);
        String uid=req.getParameter("uid");
        System.out.println(uid);
        //String uided=req.getParameter("uided");
        String iid=req.getParameter("iid");
        System.out.println(iid);
        is.addComInform(com_id,uid,iid);
    }

    /**
     * 查看该回复是否已经被该用户举报过已经被举报，返回提示信息已经举报过
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     * @auther wgd
     */
    public void findDisInform(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String dis_id=req.getParameter("did");
        String uid=req.getParameter("uid");
        Boolean flag=is.findDisInform(dis_id,uid);
        ResultInfo info = new ResultInfo();
        if (flag)
        {
            info.setFlag(true);
            info.setErrorMsg("该回复已经被举报过！");
        }else {
            info.setFlag(false);
        }
        writeValue(resp,info);
    }

    /**
     * 增加该回复的举报信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     * @auther wgd
     */
    public void disInform(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 传输的参数有dis_id/uid/dis_inform_id/iid/uided
         * 调用service方法，如果方法返回已经存在，那么返回提示信息已经举报过
         */
        String dis_id=req.getParameter("did");
        String uid=req.getParameter("uid");
        //String uided=req.getParameter("uided");
        String iid=req.getParameter("iid");
        is.addDisInform(dis_id,uid,iid);
    }

}